package com.shishuo.cms.tag;

import static freemarker.template.ObjectWrapper.BEANS_WRAPPER;

import java.io.IOException;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.shishuo.cms.entity.ClassesEntity;
import com.shishuo.cms.entity.vo.PageVo;
import com.shishuo.cms.vo.ArticleEntityVo;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
@Service
public class HotListTag extends BaseTagPlugin
{
	
	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException
	{
		String aliasName = params.get("aliasName").toString();
		try {
			ClassesEntity classesEntity=classesService.getByAliasName(aliasName);
			if (null!=classesEntity) {
				if(aliasName.equals("article")){
					PageVo<ArticleEntityVo>  pageList=articleService.getAllListPageByClassId(0,classesEntity.getId(),aliasName);
					env.setVariable("tag_list_value", BEANS_WRAPPER.wrap(pageList));
				}
			}
			env.setVariable("tag_class", BEANS_WRAPPER.wrap(classesEntity));
			body.render(env.getOut());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
